package com.beiding;

import com.beiding.codecreater.test.bo.Student;
import com.beiding.my.bomapping.BoTypeMapper;
import com.beiding.my.bomapping.BoTypeMapperHolder;
import com.beiding.my.mql.MQLBuilder;
import com.beiding.my.mql.MQLExecutor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.HashMap;
import java.util.Map;

@SpringBootApplication
public class CodecreaterApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(CodecreaterApplication.class, args);

       /* StudentFactory studentFactory = context.getBean(StudentFactory.class);
        Student student = studentFactory.createBo();

        student.setName("丁常磊");
        student.setAge(20);

        if (student.save()) {

            TeacherFactory teacherFactory = context.getBean(TeacherFactory.class);

            Teacher teacher = teacherFactory.createBo();

            teacher.setName("石满");

            if (teacher.save()) {
                if (student.attachTeacher(teacher)) {

                    System.out.println("关联成功");

                }

            }

        }

        Student bo = studentFactory.createBo();


        if (bo.query(q.eq(bo.name, "丁常磊").eq(bo.teacher.name, "石满"))) {

            Teacher teacher = bo.getTeacher();

            System.out.println(teacher.getName());

        }
*/

/*

        MapperHolder holder = context.getBean(MapperHolder.class);

        BeTypeMapper<StudentBe> mapper = holder.getMapper(StudentBe.class);

        Map<String, Object> values = new HashMap<>();
        values.put("name", "丁常磊");
        values.put("age", 18);
        StudentBe be = mapper.newBeByFieldName(values);
        System.out.println(be);
*/


//        BoTypeMapperHolder holder = context.getBean(BoTypeMapperHolder.class);

  //      BoTypeMapper<Student> mapper = holder.getBoTypeMapper(Student.class);
/*
        Map<String, Object> values = new HashMap<>();

        values.put("name", "丁常磊");
        values.put("teacher.name", "石满");

        Student student = mapper.newBoByAttributeName(values);

        System.out.println(student);*/

        MQLBuilder builder = context.getBean(MQLBuilder.class);

        MQLExecutor executor = builder.build("select student.teacher.*,student.name from Student student where student.name=:p1");


    }



    //TODO 去掉Bo 和 Be间的Vo层

    //TODO Bo层创建public的无参构造

    //TODO Bo层使用 _be 指向be层


}

